import static org.junit.Assert.*;

import java.util.Vector;

import org.junit.Test;

import TamirsGui.GuiMessage;
import TamirsGui.GuiMessage.MessageAuthorization;
import TamirsGui.GuiMessage.MessageSubType;
import TamirsGui.GuiMessage.MessageType;
import TamirsGui.MainWindowMsg;

public class handlingMessagesFromServerTests {
	String serverDelimiter = (char)1+"";

	@Test
	public void loginMessageTest() {
		MainWindowMsg parser = new MainWindowMsg();
		String messageFromServer = "login"+serverDelimiter+"member"+serverDelimiter+"success"+serverDelimiter;
		Vector<GuiMessage> afterParse = parser.parseMessage(messageFromServer);
		String body = "";
		String title ="login";
		MessageType type = MessageType.ack;
		MessageSubType subType = MessageSubType.loginAck;
		MessageAuthorization authorization = MessageAuthorization.member;
		GuiMessage actual = afterParse.elementAt(0); 
		assertEquals(title, actual.getTitle());
		assertEquals(body, actual.getBody());
		assertEquals(type, actual.getType());
		assertEquals(subType, actual.getSubType());
		assertEquals(authorization, actual.getAuthorization());

	}
	
	@Test
	public void registerMessageTest() {
		MainWindowMsg parser = new MainWindowMsg();
		String messageFromServer = "register"+serverDelimiter+"member"+serverDelimiter+"success"+serverDelimiter;
		Vector<GuiMessage> afterParse = parser.parseMessage(messageFromServer);
		String body = "";
		String title ="register";
		MessageType type = MessageType.ack;
		MessageSubType subType = MessageSubType.registerAck;
		MessageAuthorization authorization = MessageAuthorization.member;
		GuiMessage actual = afterParse.elementAt(0); 
		assertEquals(title, actual.getTitle());
		assertEquals(body, actual.getBody());
		assertEquals(type, actual.getType());
		assertEquals(subType, actual.getSubType());
		assertEquals(authorization, actual.getAuthorization());

	}
	
	@Test
	public void candidatesListMessageTest() {
		MainWindowMsg parser = new MainWindowMsg();
		String messageFromServer = "candidatesList"+serverDelimiter+"member1"+serverDelimiter+"member2"+serverDelimiter;
		Vector<GuiMessage> afterParse = parser.parseMessage(messageFromServer);
		String body = "member1";
		String title ="member1";
		MessageType type = MessageType.content;
		MessageSubType subType = MessageSubType.candidateList;
		MessageAuthorization authorization = MessageAuthorization.admin;
		GuiMessage actual = afterParse.elementAt(0); 
		assertEquals(title, actual.getTitle());
		assertEquals(body, actual.getBody());
		assertEquals(type, actual.getType());
		assertEquals(subType, actual.getSubType());
		assertEquals(authorization, actual.getAuthorization());
	}
	
	@Test
	public void moderatorsListMessageTest() {
		MainWindowMsg parser = new MainWindowMsg();
		String messageFromServer = "moderatorList"+serverDelimiter+"admin"+serverDelimiter+"member1"+serverDelimiter+"member2"+serverDelimiter;
		Vector<GuiMessage> afterParse = parser.parseMessage(messageFromServer);
		String body = "moderatorList";
		String title ="member2";
		MessageType type = MessageType.content;
		MessageSubType subType = MessageSubType.moderatorList;
		MessageAuthorization authorization = MessageAuthorization.admin;
		GuiMessage actual = afterParse.elementAt(1); 
		assertEquals(title, actual.getTitle());
		assertEquals(body, actual.getBody());
		assertEquals(type, actual.getType());
		assertEquals(subType, actual.getSubType());
		assertEquals(authorization, actual.getAuthorization());
		title ="member1";
		actual = afterParse.elementAt(0); 
		assertEquals(title, actual.getTitle());
		assertEquals(body, actual.getBody());
		assertEquals(type, actual.getType());
		assertEquals(subType, actual.getSubType());
		assertEquals(authorization, actual.getAuthorization());
	}


	

	@Test
	public void registerFailedMessageTest() {
		MainWindowMsg parser = new MainWindowMsg();
		String messageFromServer = "register"+serverDelimiter+"guest"+serverDelimiter+"failed"+serverDelimiter+"because"+serverDelimiter;
		Vector<GuiMessage> afterParse = parser.parseMessage(messageFromServer);
		String body = "failed\n";
		String title ="register";
		MessageType type = MessageType.ack;
		MessageSubType subType = MessageSubType.registerAck;
		MessageAuthorization authorization = MessageAuthorization.guest;
		GuiMessage actual = afterParse.elementAt(0); 
		assertEquals(title, actual.getTitle());
		assertEquals(body, actual.getBody());
		assertEquals(type, actual.getType());
		assertEquals(subType, actual.getSubType());
		assertEquals(authorization, actual.getAuthorization());

	}
	@Test
	public void threadMessageTest() {
		MainWindowMsg parser = new MainWindowMsg();
		String messageFromServer = "ThreadsList"+serverDelimiter+"guest"+serverDelimiter+"1:sport"+serverDelimiter+"2:s"+serverDelimiter;
		Vector<GuiMessage> afterParse = parser.parseMessage(messageFromServer);
		String body = "";
		String title ="sport";
		MessageType type = MessageType.content;
		MessageSubType subType = MessageSubType.threadMsg;
		MessageAuthorization authorization = MessageAuthorization.guest;
		GuiMessage actual = afterParse.elementAt(0); 
		assertEquals(title, actual.getTitle());
		assertEquals(body, actual.getBody());
		assertEquals(type, actual.getType());
		assertEquals(subType, actual.getSubType());
		assertEquals(authorization, actual.getAuthorization());		
	}
	
	@Test
	public void subForumListMessageTest() {
		MainWindowMsg parser = new MainWindowMsg();
		String messageFromServer = "subForumList"+serverDelimiter+"guest"+serverDelimiter+"1:sport"+serverDelimiter+"2:s"+serverDelimiter;
		Vector<GuiMessage> afterParse = parser.parseMessage(messageFromServer);
		String body = "";
		String title ="sport";
		MessageType type = MessageType.content;
		MessageSubType subType = MessageSubType.subForum;
		MessageAuthorization authorization = MessageAuthorization.guest;
		GuiMessage actual = afterParse.elementAt(0); 
		assertEquals(title, actual.getTitle());
		assertEquals(body, actual.getBody());
		assertEquals(type, actual.getType());
		assertEquals(subType, actual.getSubType());
		assertEquals(authorization, actual.getAuthorization());		
	}
	
	
	
	@Test
	public void addedSubForumMessageACKTest() {
		MainWindowMsg parser = new MainWindowMsg();
		String messageFromServer = "ModeratorRemoved"+serverDelimiter+"admin"+serverDelimiter+"failed"+serverDelimiter+"because"+serverDelimiter;
		Vector<GuiMessage> afterParse = parser.parseMessage(messageFromServer);
		String body = "admin\nfailed\n";
		String title ="ModeratorRemoved";
		MessageType type = MessageType.ack;
		MessageSubType subType = MessageSubType.moderatorRemoved;
		MessageAuthorization authorization = MessageAuthorization.guest;
		GuiMessage actual = afterParse.elementAt(0); 
		assertEquals(title, actual.getTitle());
		assertEquals(body, actual.getBody());
		assertEquals(type, actual.getType());
		assertEquals(subType, actual.getSubType());
		assertEquals(authorization, actual.getAuthorization());

	}

	@Test
	public void postListTests() {
		MainWindowMsg parser = new MainWindowMsg();
		String delimiter1 =(char)1+"";
		String delimiter2 =(char)2+"";
		String messageFromServer = "postList"+delimiter1+"admin"+delimiter1+"1:p1"+delimiter2+"owner"+delimiter2+"this is body" +
				delimiter1+"2:p2"+delimiter2+"member"+delimiter2+"this is body2"+delimiter1+"\0\n";
		Vector<GuiMessage> afterParse = parser.parseMessage(messageFromServer);
		String body = "this is body";
		String title ="p1";
		MessageType type = MessageType.content;
		MessageSubType subType = MessageSubType.postMsg;
		MessageAuthorization authorization = MessageAuthorization.owner;
		GuiMessage actual = afterParse.elementAt(0); 
		assertEquals(title, actual.getTitle());
		assertEquals(body, actual.getBody());
		assertEquals(type, actual.getType());
		assertEquals(subType, actual.getSubType());
		assertEquals(authorization, actual.getAuthorization());

	}
	@Test
	public void emptyPostListTests() {
		MainWindowMsg parser = new MainWindowMsg();
		String delimiter1 =(char)1+"";
		String delimiter2 =(char)2+"";
		String messageFromServer = "postList"+delimiter1+"admin"+delimiter1+"\0\n";
		Vector<GuiMessage> afterParse = parser.parseMessage(messageFromServer);
		String body = "";
		String title ="";
		MessageType type = MessageType.content;
		MessageSubType subType = MessageSubType.postMsg;
		MessageAuthorization authorization = MessageAuthorization.admin;
		GuiMessage actual = afterParse.elementAt(0); 
		assertEquals(title, actual.getTitle());
		assertEquals(body, actual.getBody());
		assertEquals(type, actual.getType());
		assertEquals(subType, actual.getSubType());
		assertEquals(authorization, actual.getAuthorization());

	}
}
////Login\nUserRoll\n\0\n
////Login\nUserRoll\nWhy faild\n\0\n
////subForumList\nUserRoll\n1:subForumName\n�..\n\0\n
////Register\ nUserRoll \n\0\n
////
////ThreadsList\nUserRoll\n1:Thread1\n�\n\0\n
////PostList\nUserRoll\1:post1 body\n�\n\0\n
////
////
////addedSubForum \nUserRoll \nSuccess\nSubForumId\n
////CandidatesModeratorsList\n\0\n
////CandidatesList(the word)\ nUserRoll \n CandidatesModeratorsList(the actual list)\n\0\n
////ModeratorAdded\nUserRoll \nSuccess\n\0\n
////MsgDeleted\nUserRoll\nSuccess(or Failed)\n\0\n
////SubForumDeleted\nUserRoll\nSuccess(or Failed)\n\0\n
////MsgEdited\nUserRoll\nSuccess\n\0\n
////ModeratorsRemoved\nUserRoll\nSuccess(or Failed)\n\0\n
////ModeratorsList\nUserRoll\nthe actual ModeratorsList separated with \n of the current subForum\n\0\n
